<script>
import * as api from '@/api/api.js';
import { setSearchKeywords } from '@/store/keywords.js';
import { useAppStore } from '@/store/store.js';
import { mapState, mapActions } from 'pinia';
export default {
	computed: {
		...mapState(useAppStore, ['shopping'])
	},
	onLaunch: function () {
		this.getSearchKeywords();
		this.setCartCacheList();
		this.setAddress();
	},
	onShow: function () {
		//
	},
	onHide: function () {
		//
	},
	methods: {
		...mapActions(useAppStore, {
			setItem: 'set'
		}),
		getSearchKeywords() {
			api.product.getSearchKeywords().then(({ data: result }) => {
				if (result?.success) {
					setSearchKeywords(result.data);
				}
			});
		},
		setCartCacheList() {
			api.cart.getCartList().then(({ data: result }) => {
				if (result?.success) {
					this.setItem('shopping', result?.data || []);
				}
			});
		},
		setAddress() {
			api.framework.getAddress().then(({ data: result }) => {
				const { success, data } = result;
				if (success) {
					this.setItem('address', data);
				}
			});
		}
	}
};
</script>

<style lang="scss">
/*每个页面公共css */
@import '@/uni_modules/uni-scss/index.scss';
@import '@/common/scss/index.scss';
/* #ifndef APP-NVUE */
@import '@/static/customicons.css';

// 设置整个项目的背景色
page {
	background-color: #f5f5f5;
	color: #6a6a6a;
	font-size: 28rpx;
}

/* #endif */
</style>
